from rest_framework import serializers as seria
from goods.models import SKU
from orders.models import OrderGoods,OrderInfo


class SKUSerializer(seria.ModelSerializer):

    class Meta:
        model = SKU
        fields = ('id', 'name', 'price', 'default_image_url', 'comments')


from drf_haystack import serializers
from .search_indexes import SKUIndex
class SKUSearchSerializer(serializers.HaystackSerializer):

    class Meta:
        index_classes = [SKUIndex]
        search_fields = ('text','id', 'name', 'price', 'default_image_url', 'comments')


# class SKUCommentListSerializer_B(seria.ModelSerializer):
#     user = seria.StringRelatedField(source='user.username',read_only=True)
#     class Meta:
#         model = OrderInfo
#         fields = ['user']
class SKUCommentListSerializer(seria.ModelSerializer):
    username = seria.StringRelatedField(source='order.user.username')
    class Meta:
        model = OrderGoods
        fields = ['comment','score','is_anonymous','username']
        # depth = 1

